#!/usr/bin/env bash

requirements_find_gentoo_portage()
{
  if
    eselect package-manager >/dev/null 2>&1
  then
    [[ $(eselect package-manager show | __rvm_tail -1 | __rvm_sed 's/ //g') = 'portage' ]] ||
    [[ $(eselect package-manager show | __rvm_tail -1 | __rvm_sed 's/ //g') = '(none)'  ]] || return $?
  else
    __rvm_which emerge >/dev/null 2>&1 || return $?
  fi
}

requirements_gentoo_portage_lib_installed() [[ -n "$(portageq match / "$1" 2>/dev/null)" ]]

requirements_gentoo_portage_libs_install()
{
  __rvm_try_sudo emerge "$@" || return $?
}

requirements_gentoo_portage_update_system()
{
  __rvm_try_sudo emerge --sync || return $?
}
